<template>
  <a-card :bordered="false">
    <SMSservice-form ref="realForm" @ok="getList" :disabled="disableSubmit"></SMSservice-form>
  </a-card>
</template>

<script>
import '@/assets/less/TableExpand.less'
import { mixinDevice } from '@/utils/mixin'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import SMSserviceForm from './modules/SMSserviceForm'
import axios from 'axios'
import { getAction } from '@/api/manage'

export default {
  name: 'SMSservice',
  mixins: [JeecgListMixin, mixinDevice],
  components: {
    SMSserviceForm
  },
  data() {
    return {
      description: '短信服务页面',
      // 表头
      columns: [
        {
          title: '#',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: 'center',
          customRender: function(t, r, index) {
            return parseInt(index) + 1
          }
        },
        {
          title: this.$t('阿里AccessKeyID'),
          align: 'center',
          dataIndex: 'accessKeyId'
        },
        {
          title: this.$t('阿里AccessKeySecret'),
          align: 'center',
          dataIndex: 'accessKeySecret'
        },
        {
          title: this.$t('服务器位置'),
          align: 'center',
          dataIndex: 'regionId'
        },
        {
          title: this.$t('oss存储名称'),
          align: 'center',
          dataIndex: 'bucketname'
        },
        {
          title: this.$t('备注'),
          align: 'center',
          dataIndex: 'commet'
        },
        {
          title: this.$t('操作'),
          dataIndex: 'action',
          align: 'center',
          fixed: 'right',
          width: 147,
          scopedSlots: { customRender: 'action' }
        }
      ],
      url: {
        list: '/oss/bisAliOss/list',
        delete: '/oss/bisAliOss/delete',
        deleteBatch: '/oss/bisAliOss/deleteBatch',
        exportXlsUrl: '/oss/bisAliOss/exportXls',
        importExcelUrl: 'oss/bisAliOss/importExcel'
      },
      dictOptions: {},
      superFieldList: [],
      disableSubmit: false,
      isCustom: true
    }
  },
  created() {
    this.getSuperFieldList()
  },
  computed: {
    importExcelUrl: function() {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`
    }
  },
  watch: {
    dataSource(list) {
      if (list.length > 0) {
        this.$refs.realForm.edit(list[0])
      } else {
        this.$refs.realForm.add()
      }
    }
  },
  methods: {
    initDictConfig() {
      let that = this
      that.getInfo()
    },
    getInfo() {
      let that = this
      axios.all([that.r1(), that.r2(), that.r3(), that.query("smsType"), that.query("smsAccessKeyId"), 
        that.query("smsAccessKeySecret"), that.query("smsSignName"), that.query("smsTemplateCode")]).then(
        axios.spread((r1, r2, r3, r4, r5, r6, r7, r8) => {
          let dtl={
            smsType: '0'
          }
          if(r1.success){
            dtl.idKey=r1.result.id
            dtl.accountId=r1.result.svalue
          }
          if(r2.success){
            dtl.pwdKey=r2.result.id
            dtl.accountPwd=r2.result.svalue
          }
          if(r3.success){
            dtl.sKey=r3.result.id
            dtl.sign=r3.result.svalue
          }
          if(r4.success){
            dtl.stKey=r4.result.id
            dtl.smsType = r4.result.ivalue.toString()
          }
          if(r5.success){
            dtl.siKey=r5.result.id
            dtl.smsAccessKeyId = r5.result.svalue
          }
          if(r6.success){
            dtl.ssKey=r6.result.id
            dtl.smsAccessKeySecret = r6.result.svalue
          }
          if(r7.success){
            dtl.snKey=r7.result.id
            dtl.smsSignName = r7.result.svalue
          }
          if(r8.success){
            dtl.scKey=r8.result.id
            dtl.smsTemplateCode = r8.result.svalue
          }
          that.$refs.realForm.edit(dtl)
        })
      )
    },
    r1() {
      let that = this
      return getAction('/bis/bisSysParameter/queryByName', { name: 'shumiAccountId' })
    },
    r2() {
      let that = this
      return getAction('/bis/bisSysParameter/queryByName', { name: 'shumiAccountPwd' })
    },
    r3() {
      let that = this
      return getAction('/bis/bisSysParameter/queryByName', { name: 'shumiSign' })
    },
    query(name) {
      let that = this
      return getAction('/bis/bisSysParameter/queryByName', { name: name })
    },
    getSuperFieldList() {
      let fieldList = []
      fieldList.push({ type: 'string', value: 'accessKeyId', text: this.$t('阿里AccessKeyID'), dictCode: '' })
      fieldList.push({ type: 'string', value: 'accessKeySecret', text: this.$t('阿里AccessKeySecret'), dictCode: '' })
      fieldList.push({ type: 'string', value: 'regionId', text: this.$t('服务器位置'), dictCode: '' })
      fieldList.push({ type: 'string', value: 'bucketname', text: this.$t('oss存储名称'), dictCode: '' })
      fieldList.push({ type: 'string', value: 'commet', text: this.$t('备注'), dictCode: '' })
      this.superFieldList = fieldList
    },
    getList() {
      this.getInfo()
    }
  }
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>